package cn.tedu.rms.branch.controller;

import cn.tedu.rms.base.response.JsonResult;
import cn.tedu.rms.branch.pojo.dto.BranchQuery;
import cn.tedu.rms.branch.pojo.dto.BranchSaveParam;
import cn.tedu.rms.branch.pojo.vo.BranchVO;
import cn.tedu.rms.branch.service.BranchService;
import cn.tedu.rms.comment.pojo.dto.CommentQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "分店管理")
@Slf4j
@RequestMapping("/v1/branch")
public class BranchController {
    @Autowired
    BranchService branchService;

    @GetMapping("/select")
    public JsonResult selectBranch(BranchQuery branchQuery){
        log.debug("查询分店:参数={}",branchQuery);
        List<BranchVO> list=branchService.selectBranch(branchQuery);
        return JsonResult.ok(list);
    }
    @GetMapping("/selectById")
    public JsonResult selectById(Long id){
        log.debug("根据id查询分店，参数：{}",id);
        BranchVO branchVO = branchService.selectById(id);
        return JsonResult.ok(branchVO);
    }

    @ApiOperation(value = "根据id查询分店信息及评论")
    @GetMapping("/selectBranchComment")
    public JsonResult selectBranchCommentByBrId(CommentQuery commentQuery){
        // 通过id查询分店信息及该分店的所有评论
        log.debug("根据id查询分店评论，参数：{}",commentQuery);
        BranchVO branchVO=branchService.selectBranchComment(commentQuery);
        return JsonResult.ok(branchVO);
    }

    @PostMapping("/updateStatusById/{id}/{status}")
    public JsonResult updateStatusById(@PathVariable Long id,@PathVariable String status){
        log.debug("根据id修改分店状态，参数：{}，{}",id,status);
        branchService.updateStatusById(id,status);
        return JsonResult.ok();
    }
    @PostMapping("/save")
    public JsonResult saveBranch(BranchSaveParam branchSaveParam){
        log.debug("保存分店信息，参数：{}",branchSaveParam);
        branchService.saveBranch(branchSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("/deleteById/{id}")
    public JsonResult deleteById(@PathVariable Long id){
        log.debug("根据id删除分店，参数：{}",id);
        branchService.deleteBranchById(id);
        return JsonResult.ok();
    }
    @GetMapping("/selectByContent/{content}")
    public JsonResult deleteById(@PathVariable String content){
        log.debug("根据搜索框内容查询分店业务，参数：{}",content);
        List<BranchVO> branchVOList = branchService.selectByContent(content);
        return JsonResult.ok(branchVOList);
    }

}
